package model.playingfield;

import java.awt.Color;
import java.io.Serializable;

import model.Player;

/**
 * This is a Spot. It is an area of the PlayingField which
 * can be occupied by one and only one player piece.
 */
public class Spot implements Serializable{		
	private static final long serialVersionUID = 6959394471002688477L;
	
	private final int index;
	private Piece occupant;
	private Color color;
	private Player owner;
	private Spot nextSpot;
	
	public Spot(Color color, int index) {
		this.color = color;
		this.occupant = null;
		this.index = index;
	}
	
	public Spot(Player player, int index) {
		this.color = player.getPlayerColor();
		this.occupant = null;
		this.index = index;
		this.owner = player;
	}
	
	// Added to override a very annoying Eclipse bug
	 public Spot(){index = 0;}

	public boolean isOccupied() {
		return occupant != null;
	}
	
	public Piece getOccupant() {
		return occupant;
	}

	// TODO : add Exception class for handling illegal behavior
	public void setOccupant(Piece occupant) {
		this.occupant = occupant;	
	}
	
	public void removeOccupant() {
		this.occupant = null;
	}
	
	public int getIndex() {
		return index;
	}
	
	public Player getOwner(){
		return this.owner;
	}
	
	public void setOwner(Player player) {
		this.owner = player;
		this.color = player.getPlayerColor();
	}
	
	public void setNextSpot(Spot nextSpot) {
		this.nextSpot = nextSpot;
	}
	
	public Spot getNextSpot() {
		return this.nextSpot;
	}
} // class Spot
